/* $Header: status.h,v 2.4 02/04/25 13:22:56 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  status.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* COMMENT:  Define data structures used in Instrument Status and      */
/*           external declarations.                                    */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef I_STATUS_H
#define I_STATUS_H


/*****************************/
/*   IFDEFS                  */
/*****************************/
/*-----begin change by wangwei-----------*/
#include "zone_status.h"
/*-----end change------------------------*/

/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/


/*****************************/
/*   MACROS                  */
/*****************************/


/*****************************/
/*   TYPEDEFS                */
/*****************************/

/* Define all GC run states  */

typedef enum {
   RUN_IDLE   = 0,
   PRE_RUN    = 1,
   RUN_ACTIVE = 2,
   POST_RUN   = 3
} RUN_TYPE;

typedef U_INT32 TIME_SETPT;

typedef U_INT32 RATE_SETPT;


/* Define all signal path states  */

typedef enum
{
SIG_IDLE        = 0,       /* obtain signal data from dsp, send analog to dsp */
SIG_RETRY       = 1,       /* retry if first read attempt failed              */
SIG_ACTIVE      = 2,       /* handle compressed signals, SCC                  */
SIG1_DATA_AVAIL = 3,       /* deal with Signal1 digital data                  */
SIG2_DATA_AVAIL = 4,       /* deal with Signal2 digital data, exit to SIG_IDLE*/

SIG_ERROR       = 5,       /* handle data loss, exit to SIG_IDLE              */
SIG_DSP_FAILED  = 6        /* dead dsp, no exit, sig_path shutdown.           */
} SIG_STATE;

/* Structures used by display routines */

typedef struct
{
  BIT8 blink_image[81];         /* position 0 contains "home" character */
  BIT8 normal_image[81];        /* position 0 contains "home" character */
  INT16 offset;                 /* next char to be written to hardware */
  INT16 next_index;             /* start index of next empty display line */
  INT16 count;                  /* used for display blink duty cycle */
} DISP_IMAGE;




typedef INT16   TEMP_DISPLAY;

/* Structures used by Data Transfer Routines */

        /* Detector DSP In Structs */

typedef struct
{
        INT32   sig_out_100;    /* 100 Hz data (32 bit signed)                */
        INT32   sig_out_hi[5];  /* digital path data, MS-bytes                */
        INT16   sig_out_lo[5];  /* digital path data, LS_byte                 */
        U_INT16 sig_count;      /* # digital data pts (0-5)                   */
} SIG_IN;                       /* for signal path data from the DSP          */

typedef struct
{
        SIG_IN  signal1_data;   /* analog and digital signal #1 data          */
        U_INT16 start_run_count;/* start run count (16 bit unsigned 0-160)    */
        SIG_IN  signal2_data;   /* analog and digital signal #2 data          */
        INT8    deta_2nd;       /* detector A data from 2nd order h/w         */
        INT8    deta_1st;       /* detector A data from 1st order h/w         */
        INT32   deta_data;      /* detector A data before select and combine  */
        INT32   detb_data;      /* detector B data before select and combine  */
        INT8    detb_2nd;       /* detector B data from 2nd order h/w         */
        INT8    detb_1st;       /* detector B data from 1st order h/w         */
        INT16   checksum;       /* DSP_IN structure check sum                 */
} DSP_IN;                       /* for data received from the DSP             */


extern INT32 Deta_Data;       /* detector A data after any conversion is done */
extern INT32 Detb_Data;       /* detector B data after any conversion is done */

        /* Detector DSP Out Struct */

typedef struct
{
        INT32   DAC1_out_data;  /* DAC data for signal 1 (32 bit signed)      */
        INT32   DAC2_out_data;  /* DAC data for signal 2 (32 bit signed)      */
        U_INT16 deta_type;      /* type of detector A                         */
        U_INT16 detb_type;      /* type of detector B                         */
        U_INT16 deta_param;     /* Detector A Offset or polarity of TCD A     */
        U_INT16 detb_param;     /* Detector B Offset or polarity of TCD B     */
        U_INT16 sig1_def;       /* signal 1 definition for select and combine */
        U_INT16 sig2_def;       /* signal 2 definition for select and combine */
        U_INT16 sig1_rate;      /* signal 1 definition for data rate          */
        U_INT16 sig2_rate;      /* signal 2 definition for data rate          */
        INT16   checksum;       /* DSP_OUT structure check sum                */

} DSP_OUT;                      /* for data transferred to the DSP            */

typedef struct
{
   IIR_FILT_INFO rdg;

} LINE_SENSE;                   /* line sense reading from the mux'ed ADC */

typedef struct
{
   unsigned start_pressed    : 1; /* b7 - start key pressed             */
   unsigned stop_pressed     : 1; /* b6 - stop key pressed              */
   unsigned meth_load        : 1; /* b5- method load occurred           */
   unsigned gc_calib_param   : 1; /* b4- calibration param has changed    */
   unsigned gc_param         : 1; /* b3- setpnt or config param changed */
   unsigned smplr_param      : 1; /* b2- Sampler parameter changed      */
   unsigned mem_reset        : 1; /* b1- Memory was reset by power fail */
   unsigned pwr_fail         : 1; /* b0- Power fail occured */
}   PARAM_MOD_BITS;

typedef  union
{
   BIT8   byte;
   PARAM_MOD_BITS bits;
} PARAM_MOD_TYPE;


typedef struct
{
   unsigned meth_directory   : 1; /* b7- method stored or deleted       */
   unsigned pres_units       : 1; /* b6- display pressure units changed */
   unsigned meth_load        : 1; /* b5- method load occurred           */
   unsigned gc_calib_param   : 1; /* b4- calibration param has changed  */
   unsigned gc_param         : 1; /* b3- setpnt or config param changed */
   unsigned seq_loaded       : 1; /* b2- sequence loaded                */
   unsigned seq_param        : 1; /* b1- sequence param changed         */
   unsigned                  : 1; /* b0- unused                         */
}   PARAM_MOD_BITS2;

typedef  union
{
   BIT8    byte;
   PARAM_MOD_BITS2 bits;
} PARAM_MOD_TYPE2;


typedef struct
{
   unsigned                  : 5; /* b11-b15 not used                   */
   unsigned run_log          : 1; /* b10- have entries in run log       */
   unsigned sequence         : 1; /* b9- sequence lock                  */
   unsigned keyboard         : 1; /* b8- dc keyboard lock               */
   unsigned start_key        : 1; /* b7- start key lock                 */
   unsigned rmt_start        : 1; /* b6- remote start lock              */
   unsigned clk_tbl          : 1; /* b5- clock tbl lock                 */
   unsigned clk_tbl_exec     : 1; /* b4- clock tbl execution lock       */
   unsigned meth_seq         : 1; /* b3- method-seq-clk_tbl lock        */
   unsigned local_kbd        : 1; /* b2- local keyboard lock            */
   unsigned service_mode     : 1; /* b1- service mode flag              */
   unsigned meth_dirty       : 1; /* b0- method dirty flag              */
}   PARAM_MOD_BITS3;

typedef  union
{
   U_INT16 word;
   PARAM_MOD_BITS3 bits;
} PARAM_MOD_TYPE3;


/* Structures for power fail recovery sequencing */

   typedef enum
   {
      PFR_IDLE       = 0,
      PFR_ZONES      = 1,
      PFR_RUN        = 2
   } RECOVERY_STATE;

/* CPF type defs */

typedef struct
{
        BIT8       label[9];       /* string to be displayed for gas */
        U_INT16   gas_allow;       /* which gas types are allowed */
} CPF_GAS_TYPE;

typedef struct
{
        BIT8       label[13];    /* string to be displayed for control */
        BIT8       format;       /* format for displaying control values */
        BIT8       bits;         /* number of bits used for this control */
            U_INT16    mask;         /* mask giving position of bits */
            BIT8       shift;        /* bit position for start of bits in word */
} CPF_CTL_TYPE;

typedef struct
{
        U_INT16    *start;      /* start address of new firmware rev */
        U_INT32    count;       /* number of bytes in new firmware rev */
} FLASH_DATA_TYPE;

/* OEM type defs */

typedef struct
{
        BIT8       label[13];   /* string to be displayed for control */

        BIT8       format;      /* "pulse_len"; time in sec till pulse reverts
                                    to OFF; copied from pneu eeprom setpoint */

        BIT8       bits;        /* "pulse_left"; Down cnts sec remaining untill
                                    pulse is automatically turned off.       */
} OEM_CTRL_TYPE;

#define pulse_len  format
#define pulse_left bits

#define LAST_OEM_GAS 3
#define LAST_OEM_CTRL 10
#define LAST_OEM_ONOFF 5


typedef struct
{
        BIT8       label[13];    /* string to be displayed for control */
} OEM_XTRL_TYPE;                 /* only 1st 7 usable if 6&7 labels are same */

typedef struct
{
        BIT8       label[13];   /* string to be displayed for control           */

        BIT8       mult;        /* perform y=mult*{(x+offset)/dvdr} conversion         */

        BIT8       dvdr;        /* perform y=mult*{(x+offset)/dvdr} conversion         */

        U_INT16    offset;      /* Note that filtering done before conversion   */

        BIT8       OldGain;     /*  for filtering ; Yn = {OldGain*Yn-1 + (16-OldGain)*Xn }/16   */

/*      U_INT16    OldValu;         for filtering ; used as Yn and Yn-1 in above eqn.

                                    Since these actuals no NOT need pwr fail protection they
                                    will be declared seperately as FDDiag1Fltr,FDDiag2Fltr,
                                    BDDiag1Fltr,BDDiag2Fltr all type U_INT16 in status.c        */

} OEM_DIAG_TYPE;

/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

#pragma SECTION DATA=manuf

    extern SERIAL_NO  Serial_No;
    extern U_INT32    Uptime_Clock;       /* cumulative power-on time in seconds */
    extern DATETIME   When_Manufactured;
    extern U_INT32    Run_Count;
    extern OVEN_TYPE  Oven_Type;

    extern DET_CONFIG DetectorA_Config;
    extern DET_CONFIG DetectorB_Config;

    extern AUX_ZONE_CONFIG Auxa_Config;
    extern AUX_ZONE_CONFIG Auxb_Config;

    extern  IP_ADDRESS_TYPE  IP_Address;
    extern  IP_ADDRESS_TYPE  Subnet;
    extern  IP_ADDRESS_TYPE  Gateway;
    extern  BIT8             LAN_bootp_mode;
    extern  U_INT16          Timeout;

#pragma SECTION UNDO

#pragma SECTION DATA=manuf2

/* unused in initial VIREO release */

#pragma SECTION UNDO


#pragma SECTION DATA=pfail

    extern INT32    Ioff_Address;
    extern INT32    Last_Ioff_Address;
    extern U_INT8   Interrupt_Level;
    extern U_INT8   Last_Interrupt_Level;
    extern U_INT8   I_Cnt;
    extern U_INT8   Last_I_Cnt;

    extern RUN_TYPE Run_State;
    extern BIT8     Blank_Run;
    extern INT8     PF_Recovery_State;
    extern BIT8     Scc_Run;
    extern BIT8     Pre_Run_Ready;
    extern BIT8     Power_Fail_Blank_Run;
    extern BIT8     PF_Check_Area_Valid; /* flag used to preserve old instrument
                                  configuration through repetitive powerfails */
    extern BIT8     Method_Dirty;
    extern BIT8     Hidden_Method_Dirty;
    extern INT8     Current_Method;
    extern INT8     Hidden_Method;

    extern INT32    Service_Count[8];

    extern U_INT16  DetSerial[MAX_DETECTORS];    /* detector serial interface
                                                    setpoints (DAC units) */
    extern INT32    DetUserSerial[MAX_DETECTORS]; /* detector serial interface
                                                     setpoints (user units) */
    extern BIT8     Skip_Power_On_Test;
    extern BIT8     Oven_Power_On_Test;
    extern U_INT8   Oven_Test_On_Time;
    extern U_INT8   Oven_Test_Off_Time;
    extern ON_OFF   Disable_Diag_Auto_Clear;

/* Parameter modified */
    extern PARAM_MOD_TYPE  Parameter_Modified[2];
    extern PARAM_MOD_TYPE2 Parameter_Modified2[2];

    extern BIT8     Message[41];


/* Channel Partner Friendly , OEM_DET info */

/* inlet thermal PIDs and names */

/* extern  U_INT16       FIThermal[6]; */
extern  BIT8          FIName[8];
/* extern  U_INT16       BIThermal[6]; */
extern  BIT8          BIName[8];


/* front detector */
/* extern  U_INT16       FDThermal[6]; */
extern  BIT8          FDName[8];
extern  BIT8          BDName[8];
extern  BIT8          GCName[21];


/* ------------------  end extern's for status.c critical code section ------------- */

extern  BIT8          OEMPollTym[2];

extern  BIT8          FDCPF;

extern  CPF_GAS_TYPE  FDGas1;
extern  CPF_GAS_TYPE  FDGas2;
extern  CPF_GAS_TYPE  FDGas3;

extern  CPF_CTL_TYPE  FDCtl1;
extern  CPF_CTL_TYPE  FDCtl2;
extern  CPF_CTL_TYPE  FDCtl3;
extern  CPF_CTL_TYPE  FDCtl4;

extern  OEM_CTRL_TYPE  FDCtrl5;
extern  OEM_XTRL_TYPE  FDXtrl6;
extern  OEM_XTRL_TYPE  FDXtrl7;

extern  OEM_DIAG_TYPE  FDDiag1;
extern  OEM_DIAG_TYPE  FDDiag2;


/* back detector */
/* extern  U_INT16       BDThermal[6]; */

extern  BIT8          BDCPF;

extern  CPF_GAS_TYPE  BDGas1;
extern  CPF_GAS_TYPE  BDGas2;
extern  CPF_GAS_TYPE  BDGas3;

extern  CPF_CTL_TYPE  BDCtl1;
extern  CPF_CTL_TYPE  BDCtl2;
extern  CPF_CTL_TYPE  BDCtl3;
extern  CPF_CTL_TYPE  BDCtl4;

extern  OEM_CTRL_TYPE  BDCtrl5;
extern  OEM_XTRL_TYPE  BDXtrl6;
extern  OEM_XTRL_TYPE  BDXtrl7;

extern  OEM_DIAG_TYPE  BDDiag1;
extern  OEM_DIAG_TYPE  BDDiag2;

extern  U_INT16       OEMDetFritFlags[2][3];

/* present info for CPF's OIM board */
extern  BIT8      OIMPresence[MAX_DETECTORS];

/* flash programming info */
extern  FLASH_DATA_TYPE Flash_Data;


#pragma SECTION UNDO

extern  BIT8           OEMPollCount[2];
extern  U_INT16        OEMPollValue[2];
extern  U_INT16        OEMPollState;

extern  BIT8           LAN_MAC_address[];
extern  BIT8           LAN_serial_number[];
extern  BIT8           LAN_software_version[];

    extern BIT8   Start_Run_Lock;
    extern BIT8   Seq_Run_Lock_Copy;
    extern BIT8   Remote_Start_Lock;
    extern BIT8   Controlled_By_Host;
    extern BIT8   Start_Run_Pending;
    extern BIT8   Stop_Run_Pending;
    extern BIT8   Run_Requested;
    extern BIT8   Run_Task_Running;
    extern BIT8   Ramps_Executed;

    extern INT32 Run_Clock;

/* Power-On, Test, and Workfile Installation results */

    extern U_INT8 PF_Reset;
    extern U_INT8 MF_Reset;
    extern BIT8   Det_DSP_Startup_Status;
    extern BIT8   Det_DSP_Status;
    extern BIT8   Pneu_FPGA_Status;
    extern U_INT16 Pneu_Dsp_Startup_Status;    /* results of pneu dsp poweron */
                                               /* selftest                    */
    extern U_INT8 DMA_FPGA_Status;
    extern U_INT8 Mux_Adc_Status;
    extern DIAG_RESULT Duart_Power_On_Status;
    extern BIT8   Initialization_Complete;
    extern BIT8   Power_On_Test_Complete;
    extern BIT8   Zone_Power_On_Complete;
    extern BIT8   DataComm_Power_On_Complete;
    extern BIT8   Offset_Measurement_Complete;
    extern BIT8   Oven_Holdoff;
    extern BIT8   Stop_Key_Pressed;
    extern RECOVERY_STATE Recovery_State;

    extern BIT8   Skip_Power_On_Test_Executed;
    extern BIT8   Oven_Power_On_Test_Executed;

/* Hardware discrete ouput latch images */
extern  BIT8    DiscreteOut1_Image;
extern  BIT8    DiscreteOut1_Diag;      /* diagnostics mode */
extern  BIT8    DiscreteOut2_Image;     /* normal operation */
extern  BIT8    DiscreteOut2_Diag;      /* diagnostics mode */
extern  BIT8    Detector_Adc_Image;

/* Hardware RESET Register Images */
extern BIT8 Reset1_Image;
extern BIT8 Reset2_Image;

/* Keyboard and LED register images */
extern  BIT8  Rows_LED1_Image;
extern  BIT8  LED1_Image;
extern  BIT8  LED2_Image;
extern  BIT8  LED1_Blink_Image;
extern  BIT8  LED2_Blink_Image;

/* Hardware Register Images */
extern  BIT8    Valve_Power_Image;      /* RAM image of settings of */
                                        /* oven, zone, valve relays */
                                        /* and valve drive bits for */
                                        /* ZONES_OUT1               */

extern  BIT8    Zones_Image;            /* RAM image of settings of */
                                        /* oven and zone drive bits */
                                        /* for ZONES_OUT2           */

extern  BIT8    Zones3_Image;           /* ZONES_OUT3 Image:        */
                                        /* Thermal Fault Bit, Inlet */
                                        /* Cryo, 24V Relays, and    */
                                        /* 24V Valves               */

extern  BIT8    Zones4_Image;           /* ZONES_OUT4 Image :       */
                                        /* Flap motor, inlet fan    */

extern  BIT8    Flap_Drive_Image;       /* Part of ZONES_OUT4:  Flap Motor   */

/* Detector DSP Data Tranfer Storage            */

extern  DSP_IN  Dsp_In;
extern  DSP_OUT Dsp_Out;

/* Temperature & Generic Mux Readings */

extern  U_INT16         Reading;
extern  U_INT16         Min_Reading;
extern  U_INT16         Max_Reading;
extern  U_INT16         Reading_Noise;
extern  IIR_FILT_INFO   Mux_Adc_Offset_Rdg;

extern  IIR_FILT_INFO   Mux_Adc_Offset2_Rdg;

extern  LINE_SENSE      Line_Sense;

/* Diagnostic Readings */

extern  U_INT16         FDDiag1Fltr;
extern  U_INT16         FDDiag2Fltr;
extern  U_INT16         BDDiag1Fltr;
extern  U_INT16         BDDiag2Fltr;

extern  U_INT16         Oven_Rdg;
extern  U_INT16         InjA_Rdg;
extern  U_INT16         InjB_Rdg;
extern  U_INT16         DetA_Rdg;
extern  U_INT16         DetB_Rdg;
extern  U_INT16         AuxA_Rdg;
extern  U_INT16         AuxB_Rdg;
extern  U_INT16         Line_Sense_Rdg;
extern  U_INT16         Gain_Offset_Rdg;
extern  U_INT16         Adc_Offset_Rdg;
extern  U_INT16         Det_Diaga_Rdg;
extern  U_INT16         Det_Diagb_Rdg;
extern  U_INT16         Det_Diagc_Rdg;
extern  U_INT16         Det_Diagd_Rdg;
extern  U_INT16         Spare1_Rdg;
extern  U_INT16         Spare2_Rdg;
extern  U_INT16         Attn1_Rdg;
extern  U_INT16         Attn2_Rdg;
extern  U_INT16         DAC1_Rdg;
extern  U_INT16         DAC2_Rdg;
extern  U_INT16         Mon_5V_Rdg;
extern  U_INT16         Mon_24V_Rdg;
extern  U_INT16         Mon_15Vpos_Rdg;
extern  U_INT16         Mon_15Vneg_Rdg;
extern  U_INT16         Pneu_24V_Rdg;

extern  BIT8            DetaDiagLinearMode;     /* is DSP mode forced to LINEAR? */
extern  BIT8            DetbDiagLinearMode;     /* is DSP mode forced to LINEAR? */
extern  BIT8            Det_Diag_Mode;          /* are det discrete outputs being modified in diag mode? */


/* Signal Path status */

extern  U_INT8          Attn_Start_Tick_Count;

extern  SIG_STATE       Sig_State;      /* signal path processing state var  */

extern  U_INT16         Analog_Err_Count; /* reduces sensitivity to single rdg failures */

/* Status for Digital Signal Path */
extern U_INT32 SigBuf_Point_Count[]; /* # pts in main data buffer */
extern U_INT16 SigBuf_Overflow[];    /* flag - main buf overflow */
extern U_INT16 FrmtBuf_Point_Count[];/* # pts in formated data buf */
extern U_INT16 Acq_On[];             /* flag - acquisition on */



/* Thermal and Diagnostic Actuals */

extern  U_INT32 Ambient_Temp;           /* ambient temperature               */

 /* status monitor - foreground communication flag */

extern BIT8 Check_For_Dead_Pcb;

/* BCD input */

extern U_INT8  BCD_Input;
extern BIT8    Skip_Multi_Setpt;

/* Channel Partner Friendly info */
extern  DET_CPF_CTL  DetCpfCtl[MAX_DETECTORS];

extern  U_INT16      FDetSerialIn;
extern  U_INT16      BDetSerialIn;

/* LDID detector status */

extern  ON_OFF       F_LDID_Plasma;
extern  ON_OFF       B_LDID_Plasma;

/* HSS status info */
extern U_INT16       HS_Vial_Not_Found;



/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/

#endif

